package com.wlyuan.open.scanner.application.handler.incr;

import com.wlyuan.open.dto.tenant.OpenDriverTenantSyncDTO;
import com.wlyuan.open.scanner.assembler.ScannerTenantAssembler;
import com.wlyuan.open.scanner.constant.ScannerCodeEnum;
import com.wlyuan.open.scanner.repository.CompanyRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @author lijing
 * @description 租户 增量 listener
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class DriverTenantIncrHandler extends BaseIncrHandler<OpenDriverTenantSyncDTO> {
    private final CompanyRepository companyRepository;

    /**
     * 单个增量同步
     *
     * @param companyId
     */
    @Override
    public OpenDriverTenantSyncDTO process(Long companyId) {
        logger.info("司机租户增量同步：{}", companyId);
        return Optional.ofNullable(companyId).map(tenantId -> {
            var tenant = companyRepository.getDriverTenantById(tenantId);
            return ScannerTenantAssembler.assembleDriver(tenant);
        }).orElse(null);
    }

    @Override
    public void incrByTenantId(Long tenantId) {

    }

    @Override
    public void incrByTime(Long tenantId, String startTime, String endTime) {

    }

    @Override
    public String getSyncType() {
        return ScannerCodeEnum.DRIVER_TENANT.getVal();
    }
}
